﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include <QTreeWidget>
#include <QIcon>
#include <QMap>
#include "QFamilyTreeWidgetUtil.h"
#include "OwnerPtr.h"

namespace gcmp
{
    class IDocument;
    class IFamily;
    class TestDropEventHandler;
}

class QFamilyTreeWidget : public QTreeWidget
{
    Q_OBJECT
public:
    QFamilyTreeWidget(QWidget *parent = NULL);
    ~QFamilyTreeWidget();

public:
    void UpdateView(gcmp::IDocument* pDoc);

protected:
    void mouseMoveEvent(QMouseEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;

public slots:
    void CreateFamilyInstance();
    void RenameFamily();
    void EditFamily();
    void LoadFamily();
    void RemoveFamily();

private slots:
    void OnFamilyTreeItemDoubleClicked(QTreeWidgetItem *item, int column);

private:
    void performDrag();
    void UpdateFamilyTreeItemContextMenu(const QList<QTreeWidgetItem*>& selectedItem);

private:
    QPoint     m_startDragPoint;
    //树的右键菜单
    QMenu* m_treeMenu;

    // 缓存图标，以避免每次从资源加载
    QIconMap m_icons;

    //自响应的默认族命令
    bool m_bShowFamilyManagementMenuItem;
    std::wstring m_CreateFamilyInstanceCmdId;
    std::wstring m_RenameFamilyCmdId;
    std::wstring m_EditFamilyCmdId;
    std::wstring m_SaveFamilyAsCmdId;
    std::wstring m_LoadFamilyCmdId;
    std::wstring m_RemoveSelectedFamliesCmdId;

    gcmp::OwnerPtr<gcmp::TestDropEventHandler> m_opDropEventHandler;
};
